%% Load the data - Select the File: 'ViscosityProfiles'
close all; clear all; clc;
PerPEO = '0pt82PEO'; % Pick Viscosity Profile
load(['.\ViscosityProfiles\',PerPEO,'.mat'])

if strcmp(PerPEO,'0pt0PEO')
    first = 4;last = 8;frameFirst = 1; frameLast = 5;
else
    first = 4; last = 8; frameFirst = 4; frameLast = 10;
end
Viscosity_profile = cat(1,mu{1,frameFirst:frameLast});
xVal = xPos(first:last); c = 0;
for f = frameFirst:frameLast
    c = c + 1; p = [];
    y_val = flip(mu{f}(first:last));
    p = polyfit(xVal,y_val,1); FittedLine{c,1} = [p];
end
Val = cell2mat(FittedLine);
figure('color',[1 1 1])
cc = 0;
for i = frameFirst:frameLast
    cc = cc + 1;
    plot(xVal,flip(mu{i}(first:last)),'o');
    hold on;
    y1 = polyval(Val(cc,:),xVal);
    plot(xVal,y1,'-');
end
hold off;
ylim([0 6.5]);
meanGrad_eta = mean(Val(:,1))
stdGrad_eta = std(Val(:,1))
%% Fit line to existing data to calculate 0.05% PEO viscosity gradient
close all; clc;
PerPEO = [0 0.1 0.25 0.5 0.82]; ViscosityGrad_ref = [0 0.79E-3 2.2E-3 3.4E-3 7.2E-3];
p = polyfit(PerPEO, ViscosityGrad_ref,2);x_eta = linspace(0,1,100);
con = [0 0.05 0.1 0.25 0.5 0.82]; ViscosityGradient_calc = (p(3)+p(2).*con + p(1).*con.^2);
Grad_0pt05PEO = p(3)+p(2)*0.05 + p(1)*0.05^2